package pta;/**
 * @author： li
 * @date： 2022-03-30 11:42
 * @version 1.0
 */
import java.util.*;
import java.io.*;
public class 查验身份证 {
    static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
    static int[] q = new int[]{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
    static char[] m =new char[]{'1','0','X','9','8','7','6','5','4','3','2'};
    static boolean check(String a){
        int sum = 0;
        for(int i=0;i<17;i++){
            if(a.charAt(i)=='X'||a.charAt(i)<'0'||a.charAt(i)>'9') return false;
            sum+=(Integer.parseInt(String.valueOf(a.charAt(i)))*q[i]);
            sum=sum%11;
        }
        return m[sum]==a.charAt(17);
    }
    public static void main(String[] args) throws IOException {
        int n = Integer.parseInt(in.readLine());
        boolean flag =true;
        while(n>0){
            String a = in.readLine();
                if(!check(a)){
                    flag=false;
                    out.write(a);
                    out.write("\n");
                }
            n--;
        }
        if(flag)
            out.write("All passed\n");
        out.flush();
        in.close();
    }
}
